$(document).ready(function() {		
	//第一次查询，无参数查询
	$.ajax( {
		type : "post",
		url : "work/MyAdvice_findMyRequestPage.action",
		success : showData
	});

	$("#firstPage").click(function(){
		var total=$("#total").text();
		var page=1;
		var maxRow=$("#maxRow").text();
		
		$("#listPerson").empty();
		$("#loadingPerson").fadeIn("slow");
		$.ajax({
  			type: "post",
  			url : "work/MyAdvice_findMyRequestPage.action",
 			data:{"total":total,"page":page,"maxRow":maxRow		     
 				 },
  			success:showData
		});
	});
	
	$("#prePage").click(function(){		
		var total=$("#total").text();
		var page=$("#page").text();
		var maxRow=$("#maxRow").text();	
		page=(parseInt(page)-1);
		
		if(page<=0){
			alert("第一页了");
			return ;
		}		
		
		$("#listPerson").empty();
		$("#loadingPerson").fadeIn("slow");
		$.ajax({
			type: "post",
			url : "work/MyAdvice_findMyRequestPage.action",
 			data:{"total":total,"page":page,"maxRow":maxRow
 				 },
  			success:showData
		});
	});
	
	$("#nextPage").click(function(){		
		var total=$("#total").text();
		var page=$("#page").text();
		page=(parseInt(page)+1);
		var maxRow=$("#maxRow").text();
		var pageCount=$("#pageCount").text();
		if(page>pageCount){
			alert("最后一页了");
			return;
		}
		
		$("#listPerson").empty();
		$("#loadingPerson").fadeIn("slow");
		$.ajax({
			type: "post",
			url : "work/MyAdvice_findMyRequestPage.action",
 			data:{"total":total,"page":page,"maxRow":maxRow
 				 },
  			success:showData
		});
	});
	
	$("#lastPage").click(function(){
		var total=$("#total").text();
		var page=$("#pageCount").text();
		var maxRow=$("#maxRow").text();		
		
		$("#listPerson").empty();
		$("#loadingPerson").fadeIn("slow");
		$.ajax({
			type: "post",
			url : "work/MyAdvice_findMyRequestPage.action",
 			data:{"total":total,"page":page,"maxRow":maxRow
 				 },
  			success:showData
		});
	});
	
	$("#jumpPage").click(function(){
		var total=$("#total").text();
		var maxRow=$("#maxRow").text();
		var pageCount=$("#pageCount").text();			
		var page=$("#jump").val();
		
		if(page>pageCount){
			alert("页数过大");
			return;
		}
		$("#listPerson").empty();
		$("#loadingPerson").fadeIn("fast");
		$.ajax({
			type: "post",
			url : "work/MyAdvice_findMyRequestPage.action",
 			data:{"total":total,"page":page,"maxRow":maxRow
 				 },
  			success:showData
		});
	});
	
	function showData(data){
		$("#listPerson").empty();	
		if(data.pageUtil.list.length == 0){
			$("#loadingPerson").hide();
			$("#nonePerson").show();
			$("#total").text(0);
			$("#page").text(0);
			$("#pageCount").text(0);
			$("#maxRow").text(0);
		}else{
			$("#listPerson").hide();
			$("#nonePerson").hide();
		    $("#loadingPerson").hide();
		    $.each(data.pageUtil.list,function(i,n){
		    	var c = "申请";
		    	if(n.c=='1001') {c="申请";}
		    	else if(n.c=='1002') {c="已读未回复";}
		    	else if(n.c=='1003') {c="已回复"}
				fillDataToHtml(n.daId, n.tbEvent.EEventname, n.b, n.daContent, n.tbUserByAdviceUId.UName, 
						n.daApplyTime, n.daLastestTime, n.daSubmitTime, c);
		  	});
		$("#listPerson").show();
		$("#total").text(data.pageUtil.total);
		$("#page").text(data.pageUtil.page);
		$("#pageCount").text(Math.ceil(data.pageUtil.total/10));
		$("#maxRow").text(data.pageUtil.maxRow);
		}
	}
	
	function fillDataToHtml(daId,EEventname,b,daContent,UName,daApplyTime,daLastestTime,daSubmitTime,c){
		var submitTime = "";
		if(daSubmitTime != null){
			submitTime = daSubmitTime.replace(/T/,' ');
		}
		var content = "";
		if(daContent != null){
			content = daContent;
		}
		var strHtml="<tr>";
		strHtml+="<td id='"+daId+"'><div><input name='read' type='radio' /></div></td>";
		strHtml+="<td ><div>"+EEventname+"</div></td>";	
		strHtml+="<td ><div>"+b+"</div></td>";
		strHtml+="<td ><div>"+content+"</div></td>";
		strHtml+="<td ><div>"+UName+"</div></td>";
		strHtml+="<td ><div>"+daApplyTime.replace(/T/,' ')+"</div></td>";
		strHtml+="<td ><div>"+daLastestTime.replace(/T/,' ')+"</div></td>";
		strHtml+="<td ><div>"+submitTime+"</div></td>";
		strHtml+="<td ><div>"+c+"</div></td>";
        strHtml+="</tr>";
        $("#listPerson").append(strHtml);
        
        var id = "#"+daId;
        $(id).click(function(){
        	//window.location.href="/ag/wzp/event_findById.action?event.EId="+eid;
        	//$('#topFrame', window.parent.document).attr("src", "wzp/event_manage_top.jsp");
        	$('#tabFrame', window.parent.document).attr("src", "work/MyAdvice_findByDaId.action?daId="+daId);
        	
        });
	}
});